﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Model;
using GtsServer.Manage.Controller;
using GtsServer.Common;

namespace GtsServer.Manage.IISPage.Ajax
{
    /// <summary>
    /// FuncPrizeParmsAjax 的摘要说明
    /// </summary>
    public class FuncPrizeParmsAjax : IHttpHandler
    {
        FuncPrizeParmsController controller = new FuncPrizeParmsController();
        public void ProcessRequest(HttpContext context)
        {
            string type = string.Empty;
            if (context.Request["action"] != null)
            {
                type = context.Request["action"];

                switch (type)
                {
                    case "GetListByPrizeID"://功能性道具参数
                        GetListByPrizeID(context);
                        break;
                    case "Add":
                        Add(context);
                        break;
                    case "Update":
                        Update(context);
                        break;
                    case "Delete":
                        Delete(context);
                        break;
                    default:
                        break;
                }
            }
        }

        private void Delete(HttpContext context)
        {
            int id = context.Request["id"] == null ? 0 : Convert.ToInt32(context.Request["id"].ToString());
            context.Response.Write(controller.Delete(id));
        }

        private void Update(HttpContext context)
        {
            int id = context.Request["id"] == null ? 0 : Convert.ToInt32(context.Request["id"].ToString());
            int eventMouldID = context.Request["eventMouldID"] == null ? 0 : Convert.ToInt32(context.Request["eventMouldID"].ToString());
            int prizeID = context.Request["prizeID"] == null ? 0 : Convert.ToInt32(context.Request["prizeID"].ToString());
            int gainPrizeID = context.Request["gainPrizeID"] == null ? 0 : Convert.ToInt32(context.Request["gainPrizeID"].ToString());
            int minValue = context.Request["minValue"] == null ? 0 : Convert.ToInt32(context.Request["minValue"].ToString());
            int maxValue = context.Request["maxValue"] == null ? 0 : Convert.ToInt32(context.Request["maxValue"].ToString());
            int floatRatio = context.Request["floatRatio"] == null ? 0 : Convert.ToInt32(context.Request["floatRatio"].ToString());
            int funcChance = context.Request["funcChance"] == null ? 0 : Convert.ToInt32(context.Request["funcChance"].ToString());
            int funcDayAstrict = context.Request["funcDayAstrict"] == null ? 0 : Convert.ToInt32(context.Request["funcDayAstrict"].ToString());
            int placePrizeID = context.Request["placePrizeID"] == null ? 0 : Convert.ToInt32(context.Request["placePrizeID"].ToString());
            int placeTime = context.Request["placeTime"] == null ? 0 : Convert.ToInt32(context.Request["placeTime"].ToString());
            int param1 = context.Request["param1"] == null ? 0 : Convert.ToInt32(context.Request["param1"].ToString());
            int param2 = context.Request["param2"] == null ? 0 : Convert.ToInt32(context.Request["param2"].ToString());

            FuncPrizeParms model = new FuncPrizeParms()
            {
                ID = id,
                EventMouldID = eventMouldID,
                PrizeID = prizeID,
                GainPrizeID = gainPrizeID,
                MinValue = minValue,
                MaxValue = maxValue,
                FloatRatio = floatRatio,
                FuncChance = funcChance,
                PlacePrizeID = placePrizeID,
                PlaceTime = placeTime,
                Param1 = param1,
                Param2 = param2,
                FuncDayAstrict = funcDayAstrict
            };
            context.Response.Write(controller.Update(model));
        }

        private void Add(HttpContext context)
        {
            int eventMouldID = context.Request["eventMouldID"] == null ? 0 : Convert.ToInt32(context.Request["eventMouldID"].ToString());
            int prizeID = context.Request["prizeID"] == null ? 0 : Convert.ToInt32(context.Request["prizeID"].ToString());
            int gainPrizeID = context.Request["gainPrizeID"] == null ? 0 : Convert.ToInt32(context.Request["gainPrizeID"].ToString());
            int minValue = context.Request["minValue"] == null ? 0 : Convert.ToInt32(context.Request["minValue"].ToString());
            int maxValue = context.Request["maxValue"] == null ? 0 : Convert.ToInt32(context.Request["maxValue"].ToString());
            int floatRatio = context.Request["floatRatio"] == null ? 0 : Convert.ToInt32(context.Request["floatRatio"].ToString());
            int funcChance = context.Request["funcChance"] == null ? 0 : Convert.ToInt32(context.Request["funcChance"].ToString());
            int funcDayAstrict = context.Request["funcDayAstrict"] == null ? 0 : Convert.ToInt32(context.Request["funcDayAstrict"].ToString());
            int placePrizeID = context.Request["placePrizeID"] == null ? 0 : Convert.ToInt32(context.Request["placePrizeID"].ToString());
            int placeTime = context.Request["placeTime"] == null ? 0 : Convert.ToInt32(context.Request["placeTime"].ToString());
            int param1 = context.Request["param1"] == null ? 0 : Convert.ToInt32(context.Request["param1"].ToString());
            int param2 = context.Request["param2"] == null ? 0 : Convert.ToInt32(context.Request["param2"].ToString());

            FuncPrizeParms model = new FuncPrizeParms()
            {
                EventMouldID = eventMouldID,
                PrizeID = prizeID,
                GainPrizeID = gainPrizeID,
                MinValue = minValue,
                MaxValue = maxValue,
                FloatRatio = floatRatio,
                FuncChance = funcChance,
                PlacePrizeID = placePrizeID,
                PlaceTime = placeTime,
                Param1 = param1,
                Param2 = param2,
                FuncDayAstrict = funcDayAstrict
            };
            context.Response.Write(controller.Add(model));
        }

        /// <summary>
        /// 功能性道具参数
        /// </summary>
        /// <param name="context"></param>
        private void GetListByPrizeID(HttpContext context)
        {
            int prizeID = Convert.ToInt32(context.Request["prizeID"].ToString());
            List<FuncPrizeParmsShow> list = controller.GetListByPrizeID(prizeID);
            string json = JsonHelper.ListToJson<FuncPrizeParmsShow>(list);
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}